/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Web.Configuration;

namespace DaveSexton.DocProject.Wizards
{
	public partial class CreateDocSiteCredentialsControl : UserControl
	{
		#region Public Properties
		public string UserName
		{
			get
			{
				return userNameTextBox.Text;
			}
		}

		public string Password
		{
			get
			{
				return passwordTextBox.Text;
			}
		}

		public FormsAuthPasswordFormat Format
		{
			get
			{
				return format;
			}
			set
			{
				format = value;

				if (value == FormsAuthPasswordFormat.Clear)
					helpLabel.Text = WizardText.CreateDocSiteCredentialsHelpTextClear;
				else
					helpLabel.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture,
						WizardText.CreateDocSiteCredentialsHelpTextHashed, format);
			}
		}
		#endregion

		#region Private / Protected
		private FormsAuthPasswordFormat format;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="CreateDocSiteCredentialsControl" /> class.
		/// </summary>
		public CreateDocSiteCredentialsControl()
		{
			InitializeComponent();
		}
		#endregion

		#region Methods
		#endregion

		#region Event Handlers
		private void CreateDocSiteCredentialsControl_Validating(object sender, CancelEventArgs e)
		{
			if (userNameTextBox.TextLength == 0 || userNameTextBox.Text.Trim().Length == 0)
			{
				errors.SetError(userNameTextBox, Resources.Text.UserNameRequired);
				e.Cancel = true;
			}
			else
				errors.SetError(userNameTextBox, null);

			if (passwordTextBox.TextLength == 0 || passwordTextBox.Text.Trim().Length == 0)
			{
				errors.SetError(passwordTextBox, Resources.Text.PasswordRequired);
				e.Cancel = true;
			}
			else
				errors.SetError(passwordTextBox, null);

			if (!string.Equals(passwordTextBox.Text, confirmPasswordTextBox.Text, StringComparison.Ordinal))
			{
				errors.SetError(confirmPasswordTextBox, Resources.Text.ConfirmPasswordError);
				e.Cancel = true;
			}
			else
				errors.SetError(confirmPasswordTextBox, null);
		}

		private void textBox_Enter(object sender, EventArgs e)
		{
			TextBox textBox = (TextBox) sender;

			textBox.SelectAll();
		}
		#endregion
	}
}
